package main.tree;

import java.util.ArrayList;
import java.util.List;

/**
 * 我自己的写的中序遍历
 * @author: kejl
 * @create: 2020-07-17 08:09
 */
public class MiddleBianli {

   static List<Integer> result = new ArrayList<Integer>();


    public static void main(String[] args) {
        TreeNode treeNode4 = new TreeNode(4,null,null);
        TreeNode treeNode5 = new TreeNode(5,null,null);
        TreeNode treeNode2 = new TreeNode(2,treeNode4,treeNode5);
        TreeNode treeNode6 = new TreeNode(6,null,null);

        TreeNode treeNode7 = new TreeNode(7,null,null);

        TreeNode treeNode3 = new TreeNode(3,treeNode6,treeNode7);
        TreeNode treeNode1 = new TreeNode(1,treeNode2,treeNode3);

        middleBianli(treeNode1);
        System.out.println(result);

    }




   static void  middleBianli(TreeNode treeNode){

       TreeNode leftTreeNode  = treeNode.getLeftnode();
       TreeNode rightTreeNode  = treeNode.getRightNode();

       if(leftTreeNode!=null){
           middleBianli(treeNode.getLeftnode());
       }
       result.add(treeNode.getNum());

       if (rightTreeNode!=null){
           middleBianli(treeNode.getRightNode());
       }





   }





   static class TreeNode{

        TreeNode(int num,TreeNode leftnode,TreeNode rightNode){
            this.num = num;
            this.leftnode = leftnode;
            this.rightNode = rightNode;
        }


        public int getNum() {
            return num;
        }

        public void setNum(int num) {
            this.num = num;
        }

        int num;
        TreeNode leftnode;
        TreeNode rightNode;


        public TreeNode getLeftnode() {
            return leftnode;
        }

        public void setLeftnode(TreeNode leftnode) {
            this.leftnode = leftnode;
        }

        public TreeNode getRightNode() {
            return rightNode;
        }

        public void setRightNode(TreeNode rightNode) {
            this.rightNode = rightNode;
        }
    }

//    class Node{
//
//        TreeNode treeNode;
//        int num;
//
//        public TreeNode getTreeNode() {
//            return treeNode;
//        }
//
//        public void setTreeNode(TreeNode treeNode) {
//            this.treeNode = treeNode;
//        }
//
//        public int getNum() {
//            return num;
//        }
//
//        public void setNum(int num) {
//            this.num = num;
//        }
//
//
//    }


}
